<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'firm-media-form',
	'enableAjaxValidation' => false,
    'htmlOptions'=>array('enctype' => 'multipart/form-data'),
));
?>

	<p class="note">
		<?php echo AdminModule::t('Поля помеченные '); ?> <span class="required">*</span> <?php echo AdminModule::t('являются обязательными'); ?>.
	</p>

	<?php echo $form->errorSummary($model); ?>
		<div class="row">
		<?php echo $form->labelEx($model,'user_id'); ?>
		<?php
            echo $form->dropDownList($model, 'user_id', GxHtml::listDataEx(Users::model()->visible()->findAllAttributes(null, true, 'usergroup_id NOT IN (4)')),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'update'=>'#dropdown_firms',
                    'data'=>array('user_id'=>'js:this.value', 'pkey'=>'user_id', 'model'=>'Firms', 'ovkey'=>'id', 'olkey' => 'title', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                )
            ));
		?>
		<?php echo $form->error($model,'user_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'firm_id'); ?>
		<?php
			$user_id = 0 < $model->user_id ? $model->user_id : 1;
			$list_data = GxHtml::listDataEx(Firms::model()->visible()->findAllAttributes(null, true, 'user_id = :uid', array(':uid' => $user_id)));
			if (0 >= count($list_data)) {
				$list_data = array(0 => AdminModule::t('Не найдено фирм для выбранного пользователя'));
			}			
			echo $form->dropDownList($model, 'firm_id', 
				$list_data, 
				array('id'=>'dropdown_firms')
			);         
		?>
		<?php echo $form->error($model,'firm_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'media_type'); ?>
		<?php //echo $form->textField($model, 'media_type');
			echo $form->dropDownList($model, 'media_type', 
				Controller::firmsMediaTypes(), 
				array('id'=>'dropdown_firms')
			);           
        ?>
		<?php echo $form->error($model,'media_type'); ?>
		</div><!-- row -->
        
		<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php if ('' != $model->name): ?>
			<div id="img_block">
				<?php echo GxHtml::image($this->getFirmImgSrc($model->name, 'firms_img_thumb'), 'name', array());
				$imgajax = array(
					'dataType'=>'json',
					'success'=>'js:function(data,status){
						if ("success" == data) {
							$("#img_block").html("");
						}
					}'
				);			 
				?>
				<?php echo GxHtml::ajaxLink(AdminModule::t('Удалить фото'), $this->createUrl('/admin/firmmedia/deleteimg', array('id'=>$model->id)), $imgajax); ?>
			</div>
		<?php endif;?>
		<?php echo $form->activeFileField($model, 'name'); ?>
		<?php echo $form->error($model,'name'); ?>
		</div><!-- row -->         
        
        
		<div class="row">
		<?php echo $form->labelEx($model,'embed_code'); ?>
		<?php echo $form->textField($model, 'embed_code', array('maxlength' => 255)); ?>
		<?php echo $form->error($model,'embed_code'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textField($model, 'description', array('maxlength' => 255)); ?>
		<?php echo $form->error($model,'description'); ?>
		</div><!-- row -->


<?php
echo GxHtml::submitButton(AdminModule::t('Сохранить'));
$this->endWidget();
?>
</div><!-- form -->